<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
     <el-table
    :data="tableData"
    style="width: 40%"
    max-height="250">
    <el-table-column
      fixed
      prop="id"
      label="id"
      width="150">
    </el-table-column>
    <el-table-column
      prop="title"
      label="姓名"
      width="120">
    </el-table-column>
    <el-table-column
      prop="author"
      label="作者"
      width="120">
    </el-table-column>
    <el-table-column
      prop="copies"
      label="数量"
      width="120">
    </el-table-column>
    <el-table-column
      fixed="right"
      label="操作"
      width="120">
      <template slot-scope="scope">
        <el-button
          @click.native.prevent="deleteRow(scope.$index, tableData)"
          type="text"
          size="small">
          移除
        </el-button>
      </template>
    </el-table-column>
  </el-table>
  <br>
<el-form ref="form" :model="form" label-width="80px" style="width: 40%; margin: 0 auto;">
  <el-form-item label="id">
    <el-input v-model="form.id"></el-input>
  </el-form-item>
  <el-form-item label="title">
    <el-input v-model="form.title"></el-input>
  </el-form-item>
  <el-form-item label="author">
    <el-input v-model="form.author"></el-input>
  </el-form-item>
  <el-form-item label="copies">
    <el-input v-model="form.copies"></el-input>
  </el-form-item>
  
  <el-form-item>
    <el-button type="primary" @click="onSubmit">立即创建</el-button>
    <el-button>取消</el-button>
  </el-form-item>
</el-form>

  </div>

  
</template>

<script>
  export default {
   methods: {
      deleteRow(index, rows) {
        rows.splice(index, 1);
      },
      onSubmit() {
        this.tableData.push(this.form);
        this.$refs.form.resetFields();
      }
    },
    data() {
      return {
        tableData: [ {"id": 1, "title": "Python编程", "author": "John Doe", "copies": 4},
                      {"id": 2, "title": "历史的秘密", "author": "Jane Smith", "copies": 3},
                      {"id": 3, "title": "宇宙探索", "author": "Emily Brown", "copies": 2},
                      {"id": 4, "title": "健康生活", "author": "Mike Johnson", "copies": 5},
                      {"id": 5, "title": "数学之美", "author": "Sarah Lee", "copies": 4},
                      {"id": 6, "title": "艺术欣赏", "author": "David White", "copies": 3},
                      {"id": 7, "title": "编程入门", "author": "Alice Green", "copies": 2},
                      {"id": 8, "title": "科幻世界", "author": "Frank Black", "copies": 5},
                      {"id": 9, "title": "自然奇观", "author": "Grace Blue", "copies": 4},
                       {"id": 10, "title": "音乐之声", "author": "Tom Red", "copies": 3}] 
                       ,form: {
          id:"",
          title:"",
          author:"",
          copies:""
        }

      }
    }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
